package ${config.basePackage}.controller;

import ${config.basePackage}.common.Result;
import ${config.basePackage}.entity.${table.className};
import ${config.basePackage}.query.${table.className}Query;
import ${config.basePackage}.service.${table.className}Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * ${table.comment} 控制器
 *
 * @author ${config.author}
 * @date ${.now?string("yyyy年MM月dd日 HH:mm:ss")}
 * @since JDK 17
 */
@RestController
@RequestMapping("/${table.className?uncap_first}")
@Tag(name = "${table.comment}接口")
@Validated
public class ${table.className}Controller {

    @Resource
    private ${table.className}Service ${table.className?uncap_first}Service;

    /**
     * 分页查询${table.comment}
     */
    @Operation(summary = "分页查询${table.comment}")
    @GetMapping("/page")
    public Result<Page<${table.className}>> page(@Validated ${table.className}Query query) {
        return Result.success(${table.className?uncap_first}Service.page(query));
    }

    /**
     * 查询所有${table.comment}
     */
    @Operation(summary = "查询所有${table.comment}")
    @GetMapping("/list")
    public Result<List<${table.className}>> list() {
        return Result.success(${table.className?uncap_first}Service.listAll());
    }

    /**
     * 根据ID查询${table.comment}
     */
    @Operation(summary = "根据ID查询${table.comment}")
    @GetMapping("/{id}")
    public Result<${table.className}> getById(@Parameter(description = "主键ID") @PathVariable <#list table.columns as column><#if column.primaryKey>${column.javaType}</#if></#list> id) {
        return Result.success(${table.className?uncap_first}Service.getById(id));
    }

    /**
     * 新增${table.comment}
     */
    @Operation(summary = "新增${table.comment}")
    @PostMapping
    public Result<Void> save(@RequestBody @Validated ${table.className} ${table.className?uncap_first}) {
        return ${table.className?uncap_first}Service.save(${table.className?uncap_first}) ? Result.success() : Result.error();
    }

    /**
     * 修改${table.comment}
     */
    @Operation(summary = "修改${table.comment}")
    @PutMapping
    public Result<Void> update(@RequestBody @Validated ${table.className} ${table.className?uncap_first}) {
        return ${table.className?uncap_first}Service.update(${table.className?uncap_first}) ? Result.success() : Result.error();
    }

    /**
     * 删除${table.comment}
     */
    @Operation(summary = "删除${table.comment}")
    @DeleteMapping("/{id}")
    public Result<Void> delete(@Parameter(description = "主键ID") @PathVariable <#list table.columns as column><#if column.primaryKey>${column.javaType}</#if></#list> id) {
        return ${table.className?uncap_first}Service.removeById(id) ? Result.success() : Result.error();
    }

    /**
     * 批量删除${table.comment}
     */
    @Operation(summary = "批量删除${table.comment}")
    @DeleteMapping("/batch")
    public Result<Void> deleteBatch(@Parameter(description = "ID集合") @RequestBody List<${table.primaryKeyType}> ids) {
        return ${table.className?uncap_first}Service.deleteBatch(ids) ? Result.success() : Result.error();
    }
} 